package gxt.visual.selection;

import gxt.visual.selection.consumer.ISelectionConsumer;
import gxt.visual.selection.event.GenericSelectionChangedEvent;
import gxt.visual.selection.listener.GenericSelectionChangedListener;
import gxt.visual.selection.provider.ISingleGenericSelectionProvider;

/**
 * This selection manager manages the selection between a producer and a consumer <br>
 * @author eugenp
 */
public class SelectionManagerGeneric< T > extends SelectionManager< T, T >{
	
	public SelectionManagerGeneric(){
		super();
	}
	
	// API
	/**
	 * @param selectionProviderToSet - IS checked for null
	 * @param selectionConsumerToSet - IS checked for null
	 */
	public final void register( final ISingleGenericSelectionProvider< T > selectionProviderToSet, final ISelectionConsumer< T > selectionConsumerToSet ){
		super.register( selectionProviderToSet );
		
		selectionProviderToSet.addSelectionChangedListener( new GenericSelectionChangedListener< T >(){
			@Override
			public void selectionChanged( final GenericSelectionChangedEvent< T > scEv ){
				final T selectedItem = scEv.getSelectedItem();
				selectionConsumerToSet.consumeSelection( selectedItem );
			}
		} );

	}

}
